﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CarRentalWeb.AutorentWebServiceReference;
using System.Text;

namespace CarRentalWeb.handlers
{
    /// <summary>
    /// Summary description for GetRegionsHandler
    /// </summary>
    public class GetRegionsHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            AutoRentEntities entity = new AutoRentEntities(new Uri(System.Web.Configuration.WebConfigurationManager.AppSettings["service"]));
            IEnumerable<Office> offices = entity.Offices;
            StringBuilder result = new StringBuilder();
            try
            {
                foreach (Office office in offices)
                {
                    result.Append("<option value='");
                    result.Append(office.Office_ID);
                    result.Append("'>");
                    result.Append(office.OfficeName);
                    result.Append("</option>");
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ex.Message.ToString());
                System.Diagnostics.Trace.WriteLine(ex.Message + " " + DateTime.Now.ToString());
            }
            context.Response.Write(result.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}